// pages/shopping/shoplist/shoplist.js
const app = getApp()
const $ = app.globalData
Page({

  /**
   * 页面的初始数据
   */
  data: {
	// 商城类型
	shoptype:0,
	// 排序方式
	sorttype:0,
	// 关键词
	name:"",
	// 页数
	page:1,
	// 一级分类
	onetypeid:-1,
	// 二级分类
	twotypeid:-1,
	// 加载更多按钮
	loadmore:true,
	// 商品合集
	goodslist:[],
	// 是否是代注册
	daizhuce:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	console.log(options)
	var that = this
	var daizhuce = options.daizhuce?options.daizhuce:false
	var name = options.name?options.name:''
	that.setData({
		onetypeid:options.tabone?options.tabone:-1,
		twotypeid:options.tabtwo?options.tabtwo:-1,
		name:name,
		daizhuce:daizhuce
	})
	that.getgoods()
  },
	// 输入框内容
	bindInput:function(e){
		console.log(e)
		this.setData({
			name:e.detail.value
		})
	},
  clickGoods:function(e){
	  var thisid = e.currentTarget.dataset.id
	  wx.navigateTo({
	  	url:"/pages/shopping/business/business?id="+thisid
	  })
  },
  pingtaigoods:function(e){
	  var that = this
	  var thisid = e.currentTarget.dataset.id
	  wx.navigateTo({
	  	url:"/pages/shopping/details/details?id="+thisid+"&goodslib=0&daizhuce="+that.data.daizhuce+"&jinhuo=1"
	  })
  },
  // 加载更多
   loadgengduo:function(){
  	  var that = this
  	  that.setData({
  		  page:that.data.page+1
  	  })
  	  that.getgoods()
  },
  // 搜索
  sousuo:function(){
	var that = this
	 that.setData({
		goodslist:[]
	 })
	 that.getgoods()
  },
  getgoods:function(){
	  var that = this
	   var goodslist = that.data.goodslist
	  wx.request({
	  	url:$.AdminUrl+"/YApi/getGoodslib",
		data:{
			name:that.data.name,
			onetypeid:that.data.onetypeid,
			twotypeid:that.data.twotypeid,
			page:that.data.page
		},
		success:function(data){
			var all = data.data.obj
			goodslist = goodslist.concat(all)
			that.setData({
				loadmore:data.data.obj.length>=10?true:false,
				goodslist:goodslist
			})
		}
	  })
  },
  // 去订单页面
  goorder:function(){
	  wx.redirectTo({
	  	url:"../order/order"
	  })
  },
   // 去我的页面
  gomy:function(){
  	  wx.redirectTo({
  	  	url:"../my/my"
  	  })
  },
})